package com.qf.myblogssm.controller;

import com.qf.myblogssm.pojo.Tarticle;
import com.qf.myblogssm.pojo.Ttag;
import com.qf.myblogssm.service.ArticleService;
import com.qf.myblogssm.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * create by 王镜 on 2019/6/18 0018 18:07
 */
@Controller
@RequestMapping("/tags")
public class TagController {
    @Autowired
    private TagService tagService;
    @Autowired
    private ArticleService articleService;
    @RequestMapping("/getTagInfo")
    public String getTagInfo(Model model){
        Map<String, List<Tarticle>> tag_map=tagService.getTagsByName();
        model.addAttribute("tag_map",tag_map);
        return "tags";
    }
    @RequestMapping("/getTagByName")
    public String getTagByName(String get,HttpServletRequest request){
        List<Tarticle> tarticle= articleService.getByTag(get);
        request.setAttribute("article_list",tarticle);
        List<Ttag> tag_ist=tagService.selectAllTags();
        request.setAttribute("tag_list",tag_ist);

        Integer number=articleService.countNumber();
        request.setAttribute("article_number",number);

        Integer sortnumber=articleService.countSortNumber();
        request.setAttribute("sort_number",sortnumber);

        Integer tagnumber=tagService.countTagNumber();
        request.setAttribute("tag_number",tagnumber);

        List<Tarticle> tarticles=articleService.getArticle_sort_count();//获取文章的分类个数
        Map<String,Integer> map=new HashMap();
        for(Tarticle tarticle1:tarticles){
            map.put(tarticle1.getSort(),tarticle1.getCounts());
        }
        request.setAttribute("sort_count_map",map);
        return "main";
    }
}
